package com.jxl.coreplay.utils
{
	import flash.display.DisplayObject;
	import flash.display.Stage;
	import flash.display.StageDisplayState;
	
	public class StageUtils
	{
		public static function toggleFullScreen(obj:DisplayObject):void
		{
			var stage:Stage = obj.stage;
			if(stage != null)
			{
				if(stage.displayState == StageDisplayState.FULL_SCREEN)
				{
					stage.displayState = StageDisplayState.NORMAL;
				}
				else
				{
					try
					{
						stage.displayState = StageDisplayState.FULL_SCREEN;
					}
					catch(err:SecurityError)
					{
						trace("Fullscreen is not allowed; make sure allowFullScreen is set to true in your embedding HTML.");
					}
				}
			}
			else
			{
				trace("Stage is null, cannot set fullscreen.");
			}
		}
		
		public static function setFullScreen(obj:DisplayObject, value:Boolean):void
		{
			var stage:Stage = obj.stage;
			if(stage != null)
			{
				if(value == true)
				{
					if(stage.displayState == StageDisplayState.NORMAL)
					{
						try
						{
							stage.displayState = StageDisplayState.FULL_SCREEN;
						}
						catch(err:SecurityError)
						{
							trace("Fullscreen is not allowed; make sure allowFullScreen is set to true in your embedding HTML.");
						}
					}
				}
				else
				{
					if(stage.displayState == StageDisplayState.FULL_SCREEN)
					{
						stage.displayState = StageDisplayState.NORMAL;
					}
				}
			}
			else
			{
				trace("Stage is null, cannot set fullscreen.");
			}
		}

	}
}